#Loading data
library(lubridate)
## Loading required package: timechange
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0 ✔ purrr 0.3.5
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ lubridate::as.difftime() masks base::as.difftime()
## ✖ lubridate::date() masks base::date()
## ✖ dplyr::filter() masks stats::filter()
## ✖ lubridate::intersect() masks base::intersect()
## ✖ dplyr::lag() masks stats::lag()
## ✖ lubridate::setdiff() masks base::setdiff()
## ✖ lubridate::union() masks base::union()
library(mdsr)
library(macleish)
## Loading required package: etl
whately_2015 %>% head(20)
## # A tibble: 20 × 8
## when tempera…¹ wind_…² wind_…³ rel_h…⁴ press…⁵ solar…⁶ rainf…⁷
## <dttm> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl>
## 1 2015-01-01 00:00:00 -9.32 1.40 225. 54.6 985 0 0
## 2 2015-01-01 00:10:00 -9.46 1.51 248. 55.4 985 0 0
## 3 2015-01-01 00:20:00 -9.44 1.62 258. 56.2 985 0 0
## 4 2015-01-01 00:30:00 -9.3 1.14 244. 56.4 985 0 0
## 5 2015-01-01 00:40:00 -9.32 1.22 238. 56.9 984 0 0
## 6 2015-01-01 00:50:00 -9.34 1.09 242. 57.2 984 0 0
## 7 2015-01-01 01:00:00 -9.3 1.17 242. 57.7 984 0 0
## 8 2015-01-01 01:10:00 -9.1 1.31 244. 58.2 984 0 0
## 9 2015-01-01 01:20:00 -9.07 1.31 226. 59.0 984 0 0
## 10 2015-01-01 01:30:00 -8.99 1.81 220 59.3 984 0 0
## 11 2015-01-01 01:40:00 -9.07 1.78 222. 59.4 984 0 0
## 12 2015-01-01 01:50:00 -9.26 1.42 222. 60 984 0 0
## 13 2015-01-01 02:00:00 -9.38 1.34 235. 60.3 984 0 0
## 14 2015-01-01 02:10:00 -9.36 1.52 225. 61.1 984 0 0
## 15 2015-01-01 02:20:00 -9.3 1.57 227. 61.8 984 0 0
## 16 2015-01-01 02:30:00 -9.27 1.50 232. 62.0 983 0 0
## 17 2015-01-01 02:40:00 -9.27 1.78 223. 62.0 983 0 0
## 18 2015-01-01 02:50:00 -9.29 1.90 219. 62.5 983 0 0
## 19 2015-01-01 03:00:00 -9.2 1.91 209. 63.0 983 0 0
## 20 2015-01-01 03:10:00 -9.22 1.91 210. 63.0 983 0 0
## # … with abbreviated variable names ¹temperature, ²wind_speed, ³wind_dir,
## # ⁴rel_humidity, ⁵pressure, ⁶solar_radiation, ⁷rainfall
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
whately <- whately_2015
#groupby date
#Change when column to datetime
whately$when <- as.Date(whately$when)
#Using pivot longer
temp_plt <- whately %>%
group_by(when) %>%
summarise(max_temp = max(temperature),
min_temp = min(temperature),
avg_temp = mean(temperature)) %>%
pivot_longer(cols = c("max_temp","min_temp","avg_temp"),
names_to = "type",values_to = "temp") %>%
ggplot(aes(x = when,y = temp, color = type)) + geom_line(linewidth = 0.3) +
scale_colour_manual(values = c("mediumturquoise","midnightblue","mediumvioletred")) +
scale_x_date(date_breaks = "months",date_labels = "%b-%y") +
theme(axis.text.x = element_text(size = 8, angle = 45))
ggplotly(temp_plt)
#Ok to do with only 3, but not good if you have a lot going on
#temp_plt <- whately %>% group_by(when) %>% summarise(max_temp = max(temperature),min_temp = min(temperature),avg_temp = mean(temperature)) %>% ggplot(aes(x=when)) + geom_line(aes(y = min_temp), color = "mediumturquoise",linewidth = 0.3) + geom_line(aes(y= max_temp), color = "midnightblue",linewidth = 0.3) + geom_line(aes(y=avg_temp),color = "mediumvioletred",linewidth = 0.3) + scale_x_date(date_breaks = "months",date_labels = "%b-%y")
#ggplotly(temp_plt)